import { request } from './request'
import type { ServicePackage, CustomPackage, PackageFeature, PaginatedResponse } from '@/types'

// ==================== 技术服务套餐 ====================

export const getServicePackages = (params: {
  page: number
  page_size: number
  status?: number
}) => {
  return request<PaginatedResponse<ServicePackage>>({
    url: '/admin/packages/service',
    method: 'get',
    params
  })
}

export const getServicePackage = (id: number) => {
  return request<ServicePackage>({
    url: `/admin/packages/service/${id}`,
    method: 'get'
  })
}

export const createServicePackage = (data: Partial<ServicePackage>) => {
  return request<ServicePackage>({
    url: '/admin/packages/service',
    method: 'post',
    data
  })
}

export const updateServicePackage = (id: number, data: Partial<ServicePackage>) => {
  return request<ServicePackage>({
    url: `/admin/packages/service/${id}`,
    method: 'put',
    data
  })
}

export const deleteServicePackage = (id: number) => {
  return request({
    url: `/admin/packages/service/${id}`,
    method: 'delete'
  })
}

// ==================== 定制开发套餐 ====================

export const getCustomPackages = (params: {
  page: number
  page_size: number
  category?: string
  status?: number
}) => {
  return request<PaginatedResponse<CustomPackage>>({
    url: '/admin/packages/custom',
    method: 'get',
    params
  })
}

export const getCustomPackage = (id: number) => {
  return request<CustomPackage>({
    url: `/admin/packages/custom/${id}`,
    method: 'get'
  })
}

export const createCustomPackage = (data: Partial<CustomPackage>) => {
  return request<CustomPackage>({
    url: '/admin/packages/custom',
    method: 'post',
    data
  })
}

export const updateCustomPackage = (id: number, data: Partial<CustomPackage>) => {
  return request<CustomPackage>({
    url: `/admin/packages/custom/${id}`,
    method: 'put',
    data
  })
}

export const deleteCustomPackage = (id: number) => {
  return request({
    url: `/admin/packages/custom/${id}`,
    method: 'delete'
  })
}

// ==================== 套餐功能对照 ====================

export const getPackageFeatures = (params: {
  page: number
  page_size: number
  feature_category?: string
  status?: number
}) => {
  return request<PaginatedResponse<PackageFeature>>({
    url: '/admin/packages/features',
    method: 'get',
    params
  })
}

export const getPackageFeature = (id: number) => {
  return request<PackageFeature>({
    url: `/admin/packages/features/${id}`,
    method: 'get'
  })
}

export const createPackageFeature = (data: Partial<PackageFeature>) => {
  return request<PackageFeature>({
    url: '/admin/packages/features',
    method: 'post',
    data
  })
}

export const updatePackageFeature = (id: number, data: Partial<PackageFeature>) => {
  return request<PackageFeature>({
    url: `/admin/packages/features/${id}`,
    method: 'put',
    data
  })
}

export const deletePackageFeature = (id: number) => {
  return request({
    url: `/admin/packages/features/${id}`,
    method: 'delete'
  })
}

